dc0571c3b50c938dc587f0d6805728e75399d0d9,addon-web-mvc-thymeleaf/addon/src/main/java/org/springframework/roo/addon/web/mvc/thymeleaf/addon/ThymeleafMetadata.java,ThymeleafMetadata,getModelAttributeMethod,#String#ServiceMetadata#FieldMetadata#,1832
Before Change
pathVariableUncapitalized);
// if (HttpMethod.PUT.equals(method)) {
bodyBuilder.appendFormalLine("if (%s.PUT.equals(%s)) {",
getNameOfJavaType(SpringJavaType.HTTP_METHOD), HTTP_METHOD_PARAM_NAME);
// pet = petService.findOneForUpdate(id);
bodyBuilder.indent();
bodyBuilder.appendFormalLine("%s = %s.%s(%s);", pathVariableUncapitalized, serviceField
.getFieldName().getSymbolName(), FIN_ONE_FOR_UPDATE_METHOD_NAME.getSymbolName(), idName);
// } else {
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("} else {");
// entity = entityService.findOne(id);
bodyBuilder.indent();
bodyBuilder.appendFormalLine("%s = %s.%s(%s);", pathVariableUncapitalized, serviceField
.getFieldName().getSymbolName(), serviceMetadata.getCurrentFindOneMethod().getMethodName()
.getSymbolName(), idName);
// }
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
// if (entity == null) {
bodyBuilder.newLine();
bodyBuilder.appendFormalLine("if (%s == null) {", pathVariableUncapitalized);
// String message = messageSource.getMessage("error_NotFound", entity, null, locale);
bodyBuilder.indent();
bodyBuilder
.appendFormalLine(
"String message = %s.getMessage(\"error_NotFound\", new Object[] {\"%s\", %s}, \"The record couldn't be found\", %s);",
MESSAGE_SOURCE, this.entity.getSimpleTypeName(), idName,
LOCALE_PARAM_NAME.getSymbolName());
// throw new NotFoundException(message);
bodyBuilder.appendFormalLine("throw new %s(message);",
getNameOfJavaType(SPRINGLETS_NOT_FOUND_EXCEPTION));
bodyBuilder.indentRemove();
// }
bodyBuilder.appendFormalLine("}");
// return entity;
bodyBuilder.appendFormalLine("return %s;", pathVariableUncapitalized);
After Change
// String message = messageSource.getMessage("error_NotFound",
// entity, null, locale);
bodyBuilder.appendFormalLine(
"String message = %s.getMessage(\"error_NotFound\", new Object[] "
+ "{\"%s\", %s}, \"The record couldn't be found\", %s);", MESSAGE_SOURCE,
this.entity.getSimpleTypeName(), idName, LOCALE_PARAM_NAME.getSymbolName());
// throw new NotFoundException(message);
bodyBuilder.appendFormalLine("throw new %s(message);",
getNameOfJavaType(SPRINGLETS_NOT_FOUND_EXCEPTION));
bodyBuilder.indentRemove();
// }
bodyBuilder.appendFormalLine("}");
} else {
// Entity entity = null;
bodyBuilder.appendFormalLine("%s %s = null;", getNameOfJavaType(entityType),
pathVariableUncapitalized);
// if (HttpMethod.PUT.equals(method)) {
bodyBuilder.appendFormalLine("if (%s.PUT.equals(%s)) {",
getNameOfJavaType(SpringJavaType.HTTP_METHOD), HTTP_METHOD_PARAM_NAME);
// pet = petService.findOneForUpdate(id);
bodyBuilder.indent();
bodyBuilder.appendFormalLine("%s = %s.%s(%s);", pathVariableUncapitalized, serviceField
.getFieldName().getSymbolName(), FIN_ONE_FOR_UPDATE_METHOD_NAME.getSymbolName(), idName);
// } else {
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("} else {");
// entity = entityService.findOne(id);
bodyBuilder.indent();
bodyBuilder.appendFormalLine("%s = %s.%s(%s);", pathVariableUncapitalized, serviceField
.getFieldName().getSymbolName(), serviceMetadata.getCurrentFindOneMethod()
.getMethodName().getSymbolName(), idName);
// }
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
// if (entity == null) {
bodyBuilder.newLine();
bodyBuilder.appendFormalLine("if (%s == null) {", pathVariableUncapitalized);
// String message = messageSource.getMessage("error_NotFound",
// entity, null, locale);
bodyBuilder.indent();
bodyBuilder
.appendFormalLine(
"String message = %s.getMessage(\"error_NotFound\", new Object[] {\"%s\", %s}, \"The record couldn't be found\", %s);",
MESSAGE_SOURCE, this.entity.getSimpleTypeName(), idName,
LOCALE_PARAM_NAME.getSymbolName());
// throw new NotFoundException(message);
bodyBuilder.appendFormalLine("throw new %s(message);",
getNameOfJavaType(SPRINGLETS_NOT_FOUND_EXCEPTION));
bodyBuilder.indentRemove();
// }
bodyBuilder.appendFormalLine("}");
}
// return entity;